<template>
  <div class="detailbar">
    <div class="item"
         v-for="(item,index) in list"
         :key="index"
         @click="currentClick(index)"
         :class='{action:currentIndex==index}'>
      {{item}}
    </div>
  </div>
</template>

<script>
export default {
  name: 'DetailBar',
  props: {
    list: {
      type: Array,
      default () {
        return []
      }
    }
  },
  data () {
    return {
      currentIndex: 0
    }
  },
  methods: {
    // 根据点击，发射不同的事件，从而显示不同的内容
    currentClick (index) {
      this.currentIndex = index
      switch (index) {
        case 0:
          this.$emit('detailBarClick', 'music');
          break
        case 1:
          this.$emit('detailBarClick', 'recommend');
          break
        case 2:
          this.$emit('detailBarClick', 'sub');
          break
      }
    }
  }
}
</script>

<style scoped>
.detailbar {
  padding: 10px 0;
  height: 49px;
  display: flex;
  align-items: center;
}
.detailbar .item {
  padding: 5px 20px;
}
.action {
  border-bottom: 3px solid #00aa85;
}
</style>
